function [coef,threshold]=coef_approx(coef,pctg)
%sets the (1-pctg) percent of the smallest coefficients to zero by hard tresholding
%
%author: Sebastian Schmelcher version: 2012-01-30




vect=[];
for i=1:length(coef)-1
    fprintf(['Initiation: Iteration ' num2str(i) ' of ' num2str(length(coef)) '\n']);
    for j=1:length(coef{i})
        fprintf('.');
        if(j==length(coef{i}))
            fprintf('\n');
        end
            vect(end+1:end+numel(coef{i}{j}))=coef{i}{j}(:);

    end
end
fprintf(['Initiation: Iteration ' num2str(length(coef)) ' of ' num2str(length(coef)) '\n']);
vect(end+1:end+numel(coef{length(coef)}))=coef{length(coef)}(:);

fprintf('Sort \n')

vect=sort(abs(vect));

n=length(vect);

threshold=vect(ceil(n-n*pctg));
clear vect;

for i=1:length(coef)-1
    fprintf(['Modifikation: Iteration  ' num2str(i) ' of ' num2str(length(coef)) '\n']);
    for j=1:length(coef{i})
        
        coef{i}{j} = coef{i}{j} .* (abs(coef{i}{j})>=threshold);
        
    end
end

fprintf(['Modifikation: Iteration  ' num2str(length(coef)) ' of ' num2str(length(coef)) '\n']);
coef{length(coef)} = coef{length(coef)} .* (abs(coef{length(coef)})>=threshold);
    

